package com.xiaohua.api.service;

import com.xiaohua.api.domain.ApiCredential;
import com.xiaohua.api.mapper.ApiCredentialMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * API凭证服务类
 *
 * @author 小花
 * @date 2025-03-29
 */
@Service
public class ApiCredentialService {
    
    private static final Logger log = LoggerFactory.getLogger(ApiCredentialService.class);
    
    @Autowired
    private ApiCredentialMapper apiCredentialMapper;
    
    /**
     * 根据API名称获取凭证
     *
     * @param apiName API名称
     * @return API凭证对象，如果未找到则返回null
     */
    public ApiCredential getCredentialByName(String apiName) {
        try {
            ApiCredential credential = apiCredentialMapper.findByApiName(apiName);
            if (credential == null) {
                log.warn("未找到名为 {} 的API凭证", apiName);
            }
            return credential;
        } catch (Exception e) {
            log.error("获取API凭证失败：{}", e.getMessage(), e);
            return null;
        }
    }
} 